<!DOCTYPE html>
<html lang="en" xmlns:th="http://www.thymeleaf.org" xmlns:shiro="http://www.w3.org/1999/xhtml">

<head th:include="css :: css">

</head>

<link href="/js/jquery.icheck/skins/square/blue.css" rel="stylesheet">
<link href="/css/bootstrap-toggle.min.css" rel="stylesheet">
<style>
    .block-flat .form-group {
        margin: 0 !important;
        padding: 0 !important;
    }
</style>
<body style="opacity: 1">
<div style="padding-top: 0">
    <div class="container-fluid">
        <div class="cl-mcont">
            <div class="row">
                <div class="col-md-12">
                    <div class="block-flat">
                        <form class="form-horizontal group-border-dashed" onsubmit="return false;" id="withdrawForm">
                            <div class="form-group">
                                <div class="input-group">
                                    <button class="btn btn-primary" type="button" id="search"><i
                                            class="fa fa-search"></i>查询
                                    </button>&nbsp;
                                    <button class="btn btn-success btn-operation" type="button"
                                            id="addTime"><i class="fa fa-plus-square-o"></i> 新增
                                    </button>
                                </div>
                            </div>
                        </form>
                    </div>
                    <div class="block-flat">
                        <div class="content">
                            <div class="table-responsive">
                                <table class="table hover" id="dataTable">
                                </table>
                            </div>
                        </div>
                    </div>
                </div>
            </div>

        </div>
    </div>
    <div class="modal fade" id="myModal1" tabindex="-1" role="dialog" aria-labelledby="updateStatusLabel">
        <div class="modal-dialog" role="document" style="width:800px;">
            <div class="modal-content">
                <div class="modal-header">
                    <button type="button" class="close" data-dismiss="modal" aria-label="Close"><span
                            aria-hidden="true">&times;</span></button>
                    <h4 class="modal-title" id="updateStatusLabel">新增出账账户</h4>
                </div>
                <div class="modal-body" style="min-height: 211px;">
                    <form class="form-horizontal" role="form" id="maintainForm">
                        <input type="hidden" id="alipayId" name="id">
                        <div class="col-sm-6">
                            <div class="form-group">
                                <label for="alipay" class="col-sm-4 control-label"><span
                                        class="text-danger"></span>账号:</label>
                                <div class="col-sm-7" style="width: 240px">
                                    <input type="text" class="form-control" id="alipay" name="otherpay">
                                </div>
                            </div>
                            <div class="form-group">
                                <label for="alipay" class="col-sm-4 control-label"><span
                                        class="text-danger"></span>限额:</label>
                                <div class="col-sm-7" style="width: 240px">
                                    <input type="text" class="form-control" id="quota" name="quota">
                                </div>
                            </div>
                        </div>
                    </form>
                </div>
                <div class="modal-footer">
                    <button type="button" class="btn btn-default" data-dismiss="modal">取消</button>
                    <button type="button" class="btn btn-primary" id="toSave">确定</button>
                </div>
            </div>
        </div>
    </div>

</div>

<div th:include="js :: js"></div>
<script type="text/javascript" th:attr="src=@{/js/jquery.form.js}"></script>
<script type="text/javascript" th:attr="src=@{/js/jquery.parser.js}"></script>
<script type="text/javascript" src="js/jquery.icheck/icheck.min.js"></script>
<script type="text/javascript">
    $(document).ready(function () {
        $('#dataTable').bootstrapTable({
            url: '/OtherpayConfigController/queryOtherpayConfig',
            height: $(window).height() - 200,
            pageSize: 30,
            pagination: true,
            pageList: [30, 50, 100],
            clickToSelect: true,
            singleSelect: true,
            uniqueId: 'id',
            queryParamsType: '',
            sidePagination: 'server',
            showFooter: true,
            responseHandler: function (res) {
                return {
                    "total": res.length,
                    "rows": res
                };
            },
            columns: [

                {
                    align: 'center',
                    formatter: function (v, row, index) {
                        return index + 1
                    }
                }, {align: 'center', field: 'id', visible: false},
                {
                    align: 'center', field: 'otherpay', title: '出账账户'
                },
                {
                    align: 'center', field: 'status', title: '状态',
                    formatter: function (v, row, index) {
                        return {0: "<span style='color:red'>关闭</span>", 1: "<span style='color:green'>开启</span>"}[v];
                    }
                },
                {
                    align: 'center', field: 'quota', title: '限额'
                },
                {
                    align: 'center', field: 'todayPayMoney', title: '当天支付总额'
                },
                {
                    align: 'center', field: 'createTime', title: '创建时间'
                },
                {
                    align: 'center', field: 'updateTime', title: '修改时间'
                },
                {
                    align: 'center', field: 'remark', title: '备注'
                }, {
                    field: 'FIELD', title: '操作', width: 136, align: 'center', formatter: function (v, row) {
                        var options;
                        if (row.status ==1) {
                            options = '<span  style="color: blue;cursor:default"  onclick="toUpdateStatus(' + row.id + ')"><input type="radio" name="statusRadio" class="updateAlipayState"  checked >开启&nbsp;</span>';
                        } else {
                            options = '<span style="cursor:default" onclick="toUpdateStatus(' + row.id + ')"><input type="radio" name="statusRadio" class="updateAlipayState" >开启&nbsp;</span>';
                        }

                        options += '<a class="label label-default" href="javascript:void(0)" onclick="toUpdate(' + row.id + ',\'' + row.otherpay + '\',' + row.quota + ')">修改</a>&nbsp;';
                        return options;
                    }
                }
            ]
        });


        $("#search").click(function () {
            reloadData();
        });

        //重载数据
        function reloadData() {
            $("#dataTable").bootstrapTable("refresh");
        }


        $("#addTime").click(function () {
            $("#updateStatusLabel").html("新增出账账户")
            $("#alipay").attr("readOnly", false);
            $("#alipayId").val("");
            $("#alipay").val("");
            $("#quota").val("");
            $("#myModal1").modal("show");
        });
    })
    $("#toSave").click(function () {
        if (($("#alipay").val() == '' || $("#quota").val() == '')) {
            layer.msg("账号和限额不可为空");
        }
        if ($("#alipayId").val() == null || $("#alipayId").val() == "") {
            $.post("/OtherpayConfigController/insertOtherpayConfig", $("#maintainForm").serialize(), function (data) {
                layer.msg(data.message);
                if (data.success) {
                    $("#myModal1").modal("hide");
                    $("#dataTable").bootstrapTable("refresh");
                }
            })
        } else {
            $.post("/OtherpayConfigController/updateOtherpayConfig", $("#maintainForm").serialize(), function (data) {
                layer.msg(data.message);
                if (data.success) {
                    $("#myModal1").modal("hide");
                    $("#dataTable").bootstrapTable("refresh");
                }
            })
        }


    })

    function toUpdate(id, alipay, quota) {
        $("#updateStatusLabel").html("修改出账账户")
        $("#alipayId").val(id);
        $("#alipay").val(alipay);
        $("#alipay").attr("readOnly", true);
        $("#quota").val(quota);
        $("#myModal1").modal("show");
    }

    function toUpdateStatus(id) {
        $.post("/OtherpayConfigController/updateOtherpayState", {"id": id}, function (data) {
            layer.msg(data.message);
            $("#dataTable").bootstrapTable("refresh");
        })
    }

</script>
</body>
</html>
